package com.personalsystem.account.bean;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import com.personalsystem.role.bean.Role;


@Entity
@Table(name="ACCOUNT")
public class Account implements Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	private Long id;
	
	private String username;
	
	private String password;
	
	private String remark;
	
	private String remarkUbb;
	
	private Set<Role> roleSet=new HashSet<Role>();
	
	private Integer status;

	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@Column(name="USERNAME")
    public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name="PASSWORD")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@Column(name="REMARK")
	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Column(name="REMARK_UBB")
	public String getRemarkUbb() {
		return remarkUbb;
	}

	public void setRemarkUbb(String remarkUbb) {
		this.remarkUbb = remarkUbb;
	}

	@Column(name="STATUS")
	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}


	@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)  
    @JoinTable(name = "ACCOUNT_ROLE",   
            joinColumns ={@JoinColumn(name = "account_role_aid", referencedColumnName = "id") },   
            inverseJoinColumns = { @JoinColumn(name = "account_role_rid", referencedColumnName = "id")   
    })  
	public Set<Role> getRoleSet() {
		return roleSet;
	}

	public void setRoleSet(Set<Role> roleSet) {
		this.roleSet = roleSet;
	}

	public void addRole(Role role) {  
        if (!this.roleSet.contains(role)) {//检测在该散列表中某些键是否映射到指定值,value 查找的值。如果某些键映射到该散列表中的值为true，否则false  
            this.roleSet.add(role);  
        }  
    }  
  
    public void removeRole(Role role) {  
        this.roleSet.remove(role);
    }  

	
}
